package com.bj58.groupbuy.action.util;

import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;

public class MyPathUtil {
//	private static String filesep=System.getProperty("file.separator");
	  public static String getRootPath()
	  {
	    File file = new File(System.getProperty("user.dir"));
	    String path = file.getAbsolutePath().replace('\\', '/');
	    path = path.substring(0, path.indexOf('/'));
	    return path;
	  }
	  
	  
	  /* 
	  * @return true---是Windows操作系统
	  */
	  public static boolean isWindowsOS(){
	      boolean isWindowsOS = false;
	      String osName = System.getProperty("os.name");
	      if(osName.toLowerCase().indexOf("windows")>-1){
	        isWindowsOS = true;
	      }
	      return isWindowsOS;
	   }
	  
	  public static String getIRPath(){
		  String path  = "";
		  if(isWindowsOS()){
			  path = getRootPath()+"\\workspace\\com.bj58.groupbuy.web.action\\src\\main\\webapp\\views\\intreport\\";
		  }else{
			  path = "/opt/web/bi.t.58.com/views/intreport/";
		  }
		  return path;
	  }
	  
	  public static String getIChartsPath(){
		  String path  = "";
		  if(isWindowsOS()){
			  path = getRootPath()+"\\workspace\\com.bj58.groupbuy.web.action\\src\\main\\webapp\\views\\intCharts\\";
		  }else{
			  path = "/opt/web/bi.t.58.com/views/intCharts/";
		  }
		  return path;
	  }
	  
	  
	  public static String getIEPath(){
		  String path  = "";
		  if(isWindowsOS()){
			  path = getRootPath()+"/workspace/com.bj58.groupbuy.web.action/src/main/webapp/views/intemail/";
		  }else{
			  path = "/opt/web/bi.t.58.com/views/intemail/";
		  }
		  return path;
	  }
	  
	  
	  public static String getDocSavePath(){
		  String path  = "";
		  if(isWindowsOS()){
			  path = getRootPath()+"/workspace/com.bj58.groupbuy.web.action/src/main/webapp/resources/documents/";
		  }else{
			  path = "/opt/web/bi.t.58.com/resources/documents/";
		  }
		  return path;
	  }
	  public static String getZipSavePath(){
		  String path  = "";
		  if(isWindowsOS()){
			  path = getRootPath()+"/workspace/com.bj58.groupbuy.web.action/src/main/webapp/resources/zipfiles/";
		  }else{
			  path = "/opt/web/bi.t.58.com/resources/zipfiles/";
		  }
		  return path;
	  }
	  
		public static String getTemByPath(String path)throws Exception{
			ResourcesUtil.setCharset(Charset.forName("utf-8"));
			FileInputStream inputStream = new FileInputStream(new File(path));
			String templateContext = ResourcesUtil.readString2(inputStream);
			return templateContext;
		}
}
